package cn.liccshop.core.service.dataCenter.controller;

import cn.liccshop.core.service.dataCenter.service.IDataCenterService;
import cn.liccshop.core.utils.ObjectToOtherUtils;
import cn.liccshop.sys.constants.Constants;
import cn.liccshop.sys.entity.Result;
import cn.liccshop.sys.exception.MySystemException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author LiCC
 * @program LiCCShop
 * @description 数据中心Controller
 * @since 2019-05-27-01:58
 */
@RestController
@RequestMapping("/dataCenter")
public class DataCenterController {
    @Autowired
    private IDataCenterService iDataCenterService;

    /**
     * 数据中心获取销售相关数据
     * @param map
     * @return
     * @throws MySystemException
     */
    @RequestMapping(value = "goodsSales")
    public Result getGoodsSalesData(@RequestBody Map<String, Object> map) throws MySystemException {
        String beginDate = ObjectToOtherUtils.toString(map.get("beginDate"));
        String endDate = ObjectToOtherUtils.toString(map.get("endDate"));
        if (StringUtils.isBlank(beginDate)||StringUtils.isBlank(endDate)){
            /** 开始或结束时间未空 **/
            throw new MySystemException("参数异常", Constants.INVALID_PARM);
        }
        Map<String, Object> data = iDataCenterService.getGoodsSalesData(beginDate, endDate);
        return new Result().setCode(Constants.OK).setData(data).setMessage("获取数据成功");
    }
}
